package com.chinanet.netelementmodel;

import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.webservice.AttrsIn;
import com.chinanet.utils.webservice.WebService;

import java.util.HashMap;
import java.util.Map;

/**
 * IVPN_WebService_Imp_Getivpncjwsxx
 * IVPN超级无绳查询
 * @author xuzhi
 *
 */
public class IVPN_WebService_Imp_Getivpncjwsxx implements WorkInterFace {

	@Override
	public String getName() {
		return "IVPN超级无绳查询";
	}

	@Override
	public String getDesciption() {
		return "";
	}

	@Override
	public int getVersion() {
		return 0;
	}

	@Override
	public Attr[] getInAttrs() {
		Attr[] in=new Attr[1];
		in[0]=new Attr("mdn","mdn", AttrType.TYPE_String,true);
		return in;
	}

	@Override
	public Attr[] getOutAttrs() {
		Attr[] out = new Attr[9];
		out[0]=new Attr("ReturnCode", "0：成功；其它：失败", AttrType.TYPE_Int, true);
		out[1]=new Attr("Report", "返回report", AttrType.TYPE_String, true);
		out[2]=new Attr("手机号码", "手机号码", AttrType.TYPE_String, true);
		out[3]=new Attr("固网或小灵通号码", "固网或小灵通号码", AttrType.TYPE_String, true);
		out[4]=new Attr("使用区域", "使用区域", AttrType.TYPE_String, true);
		out[5]=new Attr("本机状态控制权限", "本机状态控制权限", AttrType.TYPE_String, true);
		out[6]=new Attr("用户状态", "用户状态", AttrType.TYPE_String, true);
		out[7]=new Attr("log", "服务器返回的soapxml", AttrType.TYPE_String, true);
		out[8]=new Attr("Errormsg", "服务器返回的错误信息,当ReturnCode为0的时候就不必去读取", AttrType.TYPE_String, false);
		return out;
	}

	@Override
	public Map<String, Object> init(Map<String, Object> data) {
		AttrsIn attrsIn=new AttrsIn();
		WebService webService=new WebService();
		Map<String,Object> map=new HashMap<String, Object>();
		//Get into arguments
		attrsIn.setClientSysName("CDMA");
		attrsIn.setFunctionName("getivpncjwsxx");
		attrsIn.setRequestMessage("<mdn>"+(String) data.get("mdn")+"</mdn>");
		//Get soapxml
		String returnXml=webService.WebServiceInit(attrsIn);
		String flag=webService.getPattern("flag", returnXml);
		if(flag.equals("true")){
			map.put("ReturnCode", 0);
			map.put("Report", webService.getPattern("Report", returnXml));
			map.put("手机号码", webService.getPattern("手机号码", returnXml));
			map.put("固网或小灵通号码", webService.getPattern("固网或小灵通号码", returnXml));
			map.put("使用区域", webService.getPattern("使用区域", returnXml));
			map.put("本机状态控制权限", webService.getPattern("本机状态控制权限", returnXml));
			map.put("用户状态", webService.getPattern("用户状态", returnXml));
			map.put("log", webService.dealkouhao(returnXml));
			map.put("Errormsg", "");
			map.put("flag",1);
		}else{
			map.put("flag",0);
			map.put("ReturnCode", 1);
			map.put("Report", "");
			map.put("手机号码", "");
			map.put("固网或小灵通号码","");
			map.put("使用区域", "");
			map.put("本机状态控制权限", "");
			map.put("用户状态", "");
			map.put("log", webService.dealkouhao(returnXml));
			map.put("Errormsg", "网元侧执行出错，处理请求失败");
		}
		
		return map;
	}

}
